
use $datapath/clean/main_data.dta, clear 


**********************************************************
** Add average holdings jumps and frequency of "large" jumps

** % change:
gsort lno year
	xtset lno year
	replace Np=. if Np<0
	replace Ne=. if Ne<0

	gen dNp = 100*(Np-L1.Np)/L1.Np
	gen dNe = 100*(Ne-L1.Ne)/L1.Ne

	gen dNp_pos = dNp*(dNp>0)
	gen dNe_pos = dNe*(dNe>0)
	
	gen dvisits = 100*(visits-L1.visits)/L1.visits

** Or use logs
foreach i in p e {
	gen lN`i'=ln(N`i')
	gen dlN`i' = 100*(lN`i' - L1.lN`i')
	gen dlN`i'_pos = dlN`i'*(dlN`i'>0)

}
	gen lvisits = ln(visits)
	gen dlvisits= 100*(lvisits - L1.lvisits)
	
	gen opex = totopexp - totexpco
	

**********************************************************


label var Ne "/underline{Ebooks} // /addlinespace /hspace{2mm} Holdings"
label var dNe "/hspace{2mm} /% change in holdings"
label var dNe_pos "/hspace{2mm} /% change in holdings (pos)"
label var dlNe "/hspace{2mm} /% change in holdings"
label var dlNe_pos "/hspace{2mm} /% change in holdings (pos)"
label var Qe "/hspace{2mm} Circulation" 
label var elmatexp "/hspace{2mm} Expenditure"
label var visits "/underline{Visits} // /addlinespace /hspace{2mm} Total"

label var Np "/underline{Print books} // /addlinespace /hspace{2mm} Holdings"
label var dNp "/hspace{2mm} /% change in holdings"
label var dNp_pos "/hspace{2mm} /% change in holdings (pos)"
label var dlNp "/hspace{2mm} /% change in holdings"
label var dlNp_pos "/hspace{2mm} /% change in holdings (pos)"
label var Qp "/hspace{2mm} Circulation" 
label var prmatexp "/hspace{2mm} Expenditure"
label var dvisits "/hspace{2mm} /% change in visits"
label var dlvisits "/hspace{2mm} /% change in visits"

label var staffexp "/underline{Expenses} // /addlinespace /hspace{2mm} Staff expenses"
label var opex "/hspace{2mm} Non-collection expenses"



eststo sumby: estpost tabstat Ne dlNe Qe elmatexp Np dlNp Qp prmatexp visits dlvisits if Ne>=0 & Np>=0 & elmatexp>=0 & prmatexp>=0, stats(N mean sd median p25 p75) columns(s) 

esttab sumby, unstack replace label cells("mean(fmt(1) label(Mean)) sd(fmt(1) label(SD)) p50(fmt(1) label(Median))")  mlabels(none) gaps

esttab sumby using "$tablepath/table1_sumstats.tex", unstack replace label cells("mean(fmt(1) label(Mean)) sd(fmt(1) label(SD)) p50(fmt(1) label(Median))") booktabs mlabels(none) gaps



